package com.uls.web.controller.zsw;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.uls.quartz.domain.SysJob;
import com.uls.quartz.service.ISysJobService;
import org.quartz.SchedulerException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.uls.common.annotation.Log;
import com.uls.common.core.controller.BaseController;
import com.uls.common.core.domain.AjaxResult;
import com.uls.common.enums.BusinessType;
import com.uls.zsw.domain.ElectricityUsageInfo;
import com.uls.zsw.service.IElectricityUsageInfoService;
import com.uls.common.utils.poi.ExcelUtil;
import com.uls.common.core.page.TableDataInfo;

/**
 * 用电信息Controller
 * 
 * @author zsw
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/zsw/electricityusageInfo")
public class ElectricityUsageInfoController extends BaseController
{
    @Autowired
    private IElectricityUsageInfoService electricityUsageInfoService;

    @Autowired
    private ISysJobService jobService;

    /**
     * 查询用电信息列表
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricityusageInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ElectricityUsageInfo electricityUsageInfo)
    {
        startPage();
        List<ElectricityUsageInfo> list = electricityUsageInfoService.selectElectricityUsageInfoList(electricityUsageInfo);
        return getDataTable(list);
    }

    /**
     * 导出用电信息列表
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricityusageInfo:export')")
    @Log(title = "用电信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElectricityUsageInfo electricityUsageInfo)
    {
        List<ElectricityUsageInfo> list = electricityUsageInfoService.selectElectricityUsageInfoList(electricityUsageInfo);
        ExcelUtil<ElectricityUsageInfo> util = new ExcelUtil<ElectricityUsageInfo>(ElectricityUsageInfo.class);
        util.exportExcel(response, list, "用电信息数据");
    }

    /**
     * 获取用电信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricityusageInfo:query')")
    @GetMapping(value = "/{electricityUsageId}")
    public AjaxResult getInfo(@PathVariable("electricityUsageId") Long electricityUsageId)
    {
        return success(electricityUsageInfoService.selectElectricityUsageInfoByElectricityUsageId(electricityUsageId));
    }

    /**
     * 新增用电信息
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricityusageInfo:add')")
    @Log(title = "用电信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElectricityUsageInfo electricityUsageInfo)throws SchedulerException
    {
        AjaxResult ajaxResult=toAjax(electricityUsageInfoService.insertElectricityUsageInfo(electricityUsageInfo));
        SysJob sysJob=jobService.findJobByJobName("用电定时任务");
        if(sysJob.getStatus().equals("1")){
            sysJob.setStatus("0");
            jobService.changeStatus(sysJob);
        }
        return ajaxResult;
    }

    /**
     * 修改用电信息
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricityusageInfo:edit')")
    @Log(title = "用电信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElectricityUsageInfo electricityUsageInfo)
    {
        return toAjax(electricityUsageInfoService.updateElectricityUsageInfo(electricityUsageInfo));
    }

    /**
     * 删除用电信息
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricityusageInfo:remove')")
    @Log(title = "用电信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{electricityUsageIds}")
    public AjaxResult remove(@PathVariable Long[] electricityUsageIds)
    {
        return toAjax(electricityUsageInfoService.deleteElectricityUsageInfoByElectricityUsageIds(electricityUsageIds));
    }
}
